package com.example.demo1107.demo1;

import java.time.*;
import java.time.format.DateTimeFormatter;

public class TestTime {
    public static void main(String[] args) {
        LocalDateTime dateTime = LocalDateTime.of(2022, 9, 25, 14, 15, 26);
        LocalDateTime now = LocalDateTime.now();
        System.out.println("指定日期"+dateTime);
        System.out.println("当前系统时间"+now);

        LocalDate of = LocalDate.of(2022, 11, 23);
        LocalDate now1 = LocalDate.now();
        Period between = Period.between(of, now1);
        System.out.println(" 相差年数 " + between.getYears());
        System.out.println("between.getDays() = " + between.getDays());
        System.out.println("相差的月份 " + between.getMonths());


        LocalTime of1 = LocalTime.of(8, 11, 11);
        LocalTime now2 = LocalTime.now();
        Duration between1 = Duration.between(of1, now2);
        System.out.println("时 = " + between1.toHours());
        System.out.println("分 = " + between1.toMillis());
        System.out.println("秒 = " + between1.getSeconds());


        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = now.format(dateTimeFormatter);
        System.out.println("format = " + format);
        LocalDateTime parse = LocalDateTime.parse("2020-11-17 22:22:22", dateTimeFormatter);
        System.out.println("parse = " + parse);



        getTime();
        getDate();
    }
    private static void getTime(){
        LocalTime time = LocalTime.of(11, 11, 11);
        LocalTime now = LocalTime.now();
        System.out.println("指定时间"+time);
        System.out.println("当前时间"+now);

        System.out.println("获取时间的小时"+now.getHour());
        System.out.println("获取时间的分钟"+now.getMinute());
        System.out.println("获取时间的秒数"+now.getSecond());
        System.out.println("获取时间的纳秒"+now.getNano());




    }
    private static  void getDate(){
        LocalDate date = LocalDate.of(2011, 10, 5);
        LocalDate now = LocalDate.now();
        System.out.println("指定日期"+date);
        System.out.println("当前日期"+now);

        System.out.println("获取日期年份"+now.getYear());
        System.out.println("获取日期月份"+date.getMonth().getValue());
        System.out.println("获取日期星期"+date.getDayOfWeek().getValue());
    }

}
